<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "month_box".
 *
 * @property int $id
 * @property int $user_id
 * @property string $create_time
 * @property string $update_time
 * @property float $team_box
 * @property float $box
 * @property float $team_amount_1
 * @property float $team_amount_2
 * @property float $team_amount_3
 * @property float $team_amount_4
 * @property float $amount_1
 * @property float $amount_2
 * @property float $amount_3
 * @property float $amount_4
 */
class MonthBox extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'month_box';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['user_id'], 'integer'],
            [['create_time', 'update_time'], 'safe'],
            [['team_box'], 'required'],
            [['team_box', 'box', 'team_amount_1', 'team_amount_2', 'team_amount_3', 'team_amount_4', 'amount_1', 'amount_2', 'amount_3', 'amount_4'], 'number'],

            [['status'], 'safe']
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'user_id' => 'User ID',
            'create_time' => 'Create Time',
            'update_time' => 'Update Time',
            'team_box' => 'Team Box',
            'box' => 'Box',
            'team_amount_1' => 'Team Amount  1',
            'team_amount_2' => 'Team Amount  2',
            'team_amount_3' => 'Team Amount  3',
            'team_amount_4' => 'Team Amount  4',
            'amount_1' => 'Amount  1',
            'amount_2' => 'Amount  2',
            'amount_3' => 'Amount  3',
            'amount_4' => 'Amount  4',
        ];
    }

    public function beforeSave($insert)
    {
        if (parent::beforeSave($insert)) {
            $time = date('Y-m-d H:i:s');
            $this->update_time = $time;
            if ($insert) {
                $this->create_time = $time;
            }
            return true;
        }
        return false;
    }
}
